﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;

namespace POI.eTransmittal.Enitity
{
  public   class GeneralParameter:XPCustomObject
    {
      [Key(true)]
      public int ID;
        public const string SYSTEM_EMAIL = "Sys_Email";

  
        public const string SMTP_AUTHEN_TYPE = "SMTP_Auth";
        public const string SMTP_USER_PASS = "SMTP_User_Pass";
        public const string SMTP_PORT = "SMTP_Port";
        public const string SMTP_SERVER = "SMTP_Server";
        public const string SMTP_USE_LOCAL = "SMTP_isLocal";
        public const string SMTP_USER_NAME = "SMTP_User_Name";
        public const string SMTP_USE_SSL = "SMTP_SSL";
        public const string SHARE_FOLDER_LOCATION = "SHARE_FOLDER_LOCATION";// --> \\premierfserver\AppExtDoc$\eTransmittal\Docs
        public const string INCOMING_EMAIL_BODY = "INCOMING_EMAIL_BODY";

        public const string DEFAULT_PASSWORD = "Default_Password";
        public const string FAX_EXPRESSION = "Fax_Expression";
        public const string OUTGOING_NOTIFICATION = "Outgoing_Notification";
        public const string COORDINATOR_EMAIL_ADDRESS = "Coordinator_Email";
        public const string NOTIFICATION_LINK_URL = "Notification_Url";
        public const string ALLOWED_EXTENTION = "Allowed_Extention";
        public string ParamTitle;
        [Size(200)]
        public string ParamDesc;
        [Size(500)]
        public string ParamValue;
        public string ParamDataType;
        public int OrderNo;

        [NonPersistent, Delayed]
        public string ParamValueHide
        {
            get
            {
                string result = "";
                if (this.ParamTitle == GeneralParameter.SMTP_USER_PASS)
                {
                    result = "**********";
                }
                else
                {
                    result = ParamValue;
                }
                return result;
            }
        }

        public GeneralParameter()
            : base()
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        public GeneralParameter(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
        }
        #region AuditTrail

        public DateTime CreatedDate;

        public string CreatedBy;

        public DateTime LastChangedDate;

        public string LastChangedBy;

        public void Save(string userId)
        {
            if (CreatedBy == null || CreatedDate == DateTime.MinValue)
            {
                this.CreatedDate = DateTime.Now;
                this.CreatedBy = userId;
            }

            this.LastChangedDate = DateTime.Now;
            this.LastChangedBy = userId;

            this.Save();
        }

        #endregion
        public static void CreateParam(UnitOfWork CurrentUnitOfWork, string title, Type type, string value)
        {
            GeneralParameter prm = CurrentUnitOfWork.FindObject<GeneralParameter>(CriteriaOperator.Parse("ParamTitle = ?", title));
            if (prm == null)
            {
                prm = new GeneralParameter(CurrentUnitOfWork);
                prm.ParamTitle = title;
                prm.ParamDataType = type.ToString();
                prm.ParamValue = value;
                prm.Save();
                CurrentUnitOfWork.CommitChanges();
            }
        }
    }
}
